home *** CD-ROM | disk | FTP | other *** search
- unit PrntPrev;
-
- interface
-
- uses WinProcs, SysUtils, Graphics, Classes, Printers, Forms,
- Dialogs, DsgnIntf, WinTypes, StdCtrls, ExtCtrls, Buttons,
- Controls;
-
- { TSpecialCanvas is passed in the PrintPageEvent. It is used to print
- transparently to either the screen or the printer. All Output is sent
- to the screen or printer, but all Input (i.e., TextWidth & TextHeight)
- is received from the printer. The units the user sees are always the
- printer device units (usually pixels). This concept is very similar
- to MFC's CDC object. }
-
- type
- TCanvasMode = (cmPreview, cmPrint);
-
- PreviewException = Class(Exception);
-
- TSpecialCanvas = class
- public
- { These are the "Special" variables & procedures }
- DCanvas : TCanvas; { Display Canvas }
-
- constructor Create;
- destructor Destroy;
- procedure PostPrinterSetup; { Call after Printer Setup to init variables }
- procedure SetDisplayMode(d: TCanvas);
- procedure SetPrintMode;
-
- procedure Dump;
-
- property PageWidth: integer read FPageWidth;
- property PageHeight: integer read FPageHeight;
- property Xres: integer read FXres;
- property Yres: integer read FYres;
- property NoPrintLeft: integer read FNoPrintLeft;
- property NoPrintTop: integer read FNoPrintTop;
- property NoPrintRight: integer read FNoPrintRight;
- property NoPrintBot: integer read FNoPrintBot;
-
- { Scaling functions }
- function XInch(i : single): integer;
- function YInch(i : single): integer;
-
- { These are the variables / procedures to mimic a TCanvas }
- { Only ones missing are PenPos and Pixels }
-
- procedure Arc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: integer);
- procedure BrushCopy(const Dest: TRect; Bitmap: Graphics.TBitmap;
- const Source: TRect; Color: TColor);
- procedure Chord(X1, Y1, X2, Y2, X3, Y3, X4, Y4: integer);
- procedure CopyRect(const Dest: TRect; Canvas: TCanvas;
- const Source: TRect);
- procedure Draw(X, Y: Integer; Graphic: TGraphic);
- procedure DrawFocusRect(const Rect: TRect);
- procedure Ellipse(X1, Y1, X2, Y2: integer);
- procedure FillRect(const Rect: TRect);
- procedure FloodFill(X, Y: integer; Color: TColor; FillStyle: TFillStyle);
- procedure FrameRect(const Rect: TRect);
- procedure MoveTo(X, Y: integer);
- procedure LineTo(X, Y: integer);
- procedure Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: integer);
- procedure Polygon(const Points: array of TPoint);
- procedure Polyline(const Points: array of TPoint);
- procedure Rectangle(X1, Y1, X2, Y2: integer);
- procedure RoundRect(X1, Y1, X2, Y2, X3, Y3: integer);
- procedure StretchDraw(const Rect: TRect; Graphic: TGraphic);
-
- procedure TextOut(X, Y: integer; const Text: string);
- procedure TextRect(Rect: TRect; X, Y: integer; const Text: string);
- function TextWidth(const Text: string): integer;
- function TextHeight(const Text: string): integer;
-
- property Font:TFont read FFont write SetFont;
- property Brush:TBrush read FBrush write SetBrush;
- property Pen:TPen read FPen write SetPen;
- property CopyMode:TCopyMode read FCopyMode write SetCopyMode;
- end;
-
- { *** Print Preview Types *** }
-
- type
- { Generic Print/Print Preview Exception }
- PrintException = Class(Exception);
-
- { TPageInfo is used to pass pagination information between the print
- Preview component and the user's print events. }
-
- TPageInfo = class
- CurPage : integer; { The Current Page to Print }
- LastPage : boolean; { True if its the Last Page }
- Title : string; { Print job Title }
- end;
-
-
- { TBeginPrintEvent is called before any printing occurs. It is passed a
- NIL pointer, and it is up to the event to Create and return the TPageInfo
- object. Also note that the user may create a new object descended from
- TPageInfo, and create and return that object instead. }
-
- TBeginPrintEvent = procedure(var Info: TPageInfo) of object;
-
- { TPrintPageEvent is called for each page to be printed or previewed. The
- Page to print is indicated by TPageInfo.CurPage. The Event should
- set TPageInfo.LastPage to TRUE if it is the last page to print, other-
- wise FALSE. Title is used to inform Print Manager of the name of the
- document, and by the Print Status Window. }
-
- TPrintPageEvent = procedure(var Info: TPageInfo; SCanvas: TSpecialCanvas) of object;
-
- { TEndPrintEvent is called after the print job is completed. The event
- should free the Info object and set its value to NIL. }
-
- TEndPrintEvent = procedure(var Info: TPageInfo) of object;
-
-
- { *** PRINT PREVIEW COMPONENT *** }
-
- type
-
- { TPrintPreview - this is is! The component the user drops on the form
- to enable printing with Print Preview. }
-
- TPrintPreview = class(TComponent)
- public
- constructor Create(AOwner: TComponent); override;
- procedure PrintPreview;
- procedure Print;
- destructor Destroy; override;
- published
- property OnBeginPrint: TBeginPrintEvent read FOnBeginPrint write FOnBeginPrint;
- property OnPrintPage: TPrintPageEvent read FOnPrintPage write FOnPrintPage;
- property OnEndPrint: TEndPrintEvent read FOnEndPrint write FOnEndPrint;
- property ZoomOptions:TZoomOptions read FZoomOptions write SetZoomOptions;
- property VisibleButtons:TVisibleButtons read FVisibleButtons write SetVisibleButtons;
- property CurrentPage:integer read FCurrentPage write FCurrentPage default 1;
- property GridColor:TColor read FGridColor write FGridColor default clSilver;
- property GridWidth:integer read FGridWidth write FGridWidth default 2;
- property Title:string read FTitle write FTitle;
- property ShowGrid:boolean read FShowGrid write FShowGrid default False;
- property About:TAbout read FAbout write SetAbout;
- end;
-
- procedure Register;
-
- implementation
-